<template>
  <div class="notification-container">
    <transition-group name="slide">
      <div
        class="notification"
        v-for="(message, index) in messages"
        :key="message.id"
        :style="{ zIndex: messages.length - index }"
      >
        {{ message.text }}
      </div>
    </transition-group>
  </div>
</template>

<script>
export default {
  data() {
    return {
      messages: [],
    };
  },
  methods: {
    addNewMessage(newMessageText) {
      const newMessage = {
        id: Date.now(),
        text: newMessageText,
      };
      this.messages.unshift(newMessage);
      setTimeout(() => {
        this.removeOldestMessage();
      }, 2000);
    },
    removeOldestMessage() {
      this.messages.pop();
    },
  },
};
</script>

<style>
.notification-container {
  position: fixed;
  top: 20px;
  left: 0;
  right: 0;
  padding: 10px;
  background-color: #ffffff;
  box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.1);
  transition: top 0.5s;
  z-index: 1000;
}

.notification {
  top: 20px;
  margin-bottom: 10px;
  padding: 10px;
  background-color: #f0f0f0;
  border-radius: 5px;
  transition: transform 0.5s;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.slide-enter-active,
.slide-leave-active {
  transition: transform 0.5s;
}

.slide-enter,
.slide-leave-to {
  transform: translateY(-100%);
}
</style>